home *** CD-ROM | disk | FTP | other *** search
- /*
- * CustomIO_Lib.c
- *
- * Demo/Template for writing custom IO functions
- *
- * Custom Attribute example
- */
- #include <QD3D.h>
- #include <QD3DSet.h>
-
- #include <QD3DIO.h>
- #include <QD3DString.h>
- #include <QD3DGeometry.h>
- #include <QD3DGroup.h>
-
- #include <stdlib.h>
-
- #include "CustomAttribute_Lib.h"
-
- /*
- * This file contains the implementation for the following custom attributes
- *
- * name - contains a string object, can be attached to any object below shape
- * scle - scale, determines the relative scale of an object/group with 1 meter
- * upvt - up vector, determines the vertical orientation of an object/group
- * fwvt - forward vector, determines the front orientation of an object/group
- * url - allows you to attach an URL to an object/group
- */
-
- /*
- * Globals
- */
- static TQ3ObjectClass gNameAttributeClass = NULL,
- gScaleAttributeClass = NULL,
- gUpVectorAttributeClass = NULL,
- gForwardVectorAttributeClass = NULL,
- gW3AnchorClass = NULL,
- gW3InlineClass = NULL,
- gWWWAnchorClass = NULL;
-
-
- /*
- * These are the registration calls for the individual attributes
- */
- TQ3Status NameAttribute_Register( void);
-
- TQ3Status NameAttribute_Unregister( void);
-
- TQ3Status ScaleAttribute_Register( void);
-
- TQ3Status ScaleAttribute_Unregister( void);
-
- TQ3Status UpVectorAttribute_Register( void);
-
- TQ3Status UpVectorAttribute_Unregister( void);
-
- TQ3Status ForwardDirectionAttribute_Register( void);
-
- TQ3Status ForwardDirectionAttribute_Unregister( void);
-
- TQ3Status W3Anchor_Register( void);
-
- TQ3Status W3Anchor_UnRegister( void);
-
- TQ3Status W3Anchor_Unregister( void);
-
- TQ3Status W3Inline_Register( void);
-
- TQ3Status W3Inline_Unregister( void);
-
- TQ3Status WWWAnchor_Register( void );
-
- TQ3Status WWWAnchor_Unregister( void);
-
- /**********************************************************************************************
- *
- * PUBLIC ROUTINES FOR REGISTRATION AND UNREGISTRATION
- *
- **********************************************************************************************/
-
- void RegisterAllCustomAttributes(void)
- {
- NameAttribute_Register();
-
- ScaleAttribute_Register();
-
- UpVectorAttribute_Register();
-
- ForwardDirectionAttribute_Register();
-
- W3Anchor_Register();
-
- W3Inline_Register();
-
- WWWAnchor_Register();
- }
-
-
- void UnregisterAllCustomAttributes(void)
- {
- NameAttribute_Unregister();
-
- ScaleAttribute_Unregister();
-
- UpVectorAttribute_Unregister();
-
- ForwardDirectionAttribute_Unregister();
-
- W3Anchor_Unregister();
-
- W3Inline_Unregister();
-
- WWWAnchor_Unregister();
- }
-
- /**********************************************************************************************
- *
- * NAME custom attribute
- *
- **********************************************************************************************/
-
-
- /*
- * Utility function to add a name on an shape object, geometry object, or attribute set
- */
-
- TQ3Status SetName(TQ3Object object, char *name)
- {
- TQ3StringObject string = NULL;
- TQ3AttributeSet set = NULL;
- TQ3Status status = kQ3Success;
-
- if( Q3Object_IsType(object, kQ3SharedTypeShape) == kQ3True ) {
-
- string = Q3CString_New(name);
-
- if( string == NULL) {
- status = kQ3Failure;
- goto cleanExit;
- }
-
- if( Q3Object_IsType(object, kQ3ShapeTypeGeometry) == kQ3True ) {
-
- Q3Geometry_GetAttributeSet(object, &set);
-
- if( set == NULL ) {
- set = Q3AttributeSet_New();
- if( set == NULL ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- Q3Geometry_SetAttributeSet(object, set);
- }
- } else {
- Q3Shape_GetSet(object, &set);
-
- if( set == NULL ) {
- set = Q3Set_New();
- if( set == NULL ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- Q3Shape_SetSet(object, set);
- }
- }
-
- if( Q3Set_Add(set, kElementTypeName, &string) == kQ3Failure ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- } else if( Q3Object_IsType(object, kQ3SharedTypeSet) == kQ3True ) {
- string = Q3CString_New(name);
-
- if( string == NULL) {
- status = kQ3Failure;
- goto cleanExit;
- }
-
- if( Q3AttributeSet_Add(object, kElementTypeName, &string) == kQ3Failure ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- } else
- status = kQ3Failure;
-
- cleanExit:
- if( string )
- Q3Object_Dispose(string);
- if( set )
- Q3Object_Dispose(set);
- return status;
- }
-
- /*
- * Static Functions
- */
-
- static TQ3Status NameAttribute_Traverse(
- TQ3Object unused,
- TQ3StringObject *stringObject,
- TQ3ViewObject view)
- {
- (void) unused;
-
- if (stringObject == NULL || *stringObject == NULL)
- return kQ3Success;
-
- Q3View_SubmitWriteData(view,0,0,0);
-
- if (Q3Object_Submit( *stringObject, view) == kQ3Failure)
- return kQ3Failure;
-
- return kQ3Success;
- }
-
- static TQ3Status NameAttribute_ReadData(
- TQ3SetObject attributeSet,
- TQ3FileObject file)
- {
- TQ3StringObject stringObject;
- TQ3Status status;
-
- stringObject = Q3File_ReadObject(file);
-
- status = Q3Set_Add(attributeSet, kElementTypeName, &stringObject);
-
- Q3Object_Dispose(stringObject);
-
- /*
- Note that the string object has a reference count of 1,
- which will be taken care of in the dispose
- */
- return status;
- }
-
- static TQ3Status NameAttribute_CopyAdd(
- TQ3StringObject *src,
- TQ3StringObject *dst)
- {
- *dst = Q3Shared_GetReference(*src);
- if (*dst == NULL)
- return kQ3Failure;
-
- return kQ3Success;
- }
-
- static TQ3Status NameAttribute_CopyReplace(
- TQ3StringObject *src,
- TQ3StringObject *dst)
- {
- TQ3StringObject tempString;
-
- /*
- It is always good form to get a reference first,
- in case src and dst point to the same object
- */
-
- tempString = Q3Shared_GetReference(*src);
- if (tempString == NULL)
- return kQ3Failure;
-
- if( *src )
- Q3Object_Dispose( *src );
-
- *dst = tempString;
-
- return kQ3Success;
- }
-
- static TQ3Status NameAttribute_Delete(
- TQ3StringObject *stringObject)
- {
- if(*stringObject)
- Q3Object_Dispose(*stringObject);
- return kQ3Success;
- }
-
- TQ3Status NameAttribute_Unregister(
- void)
- {
- if ( gNameAttributeClass != NULL )
- return Q3ObjectClass_Unregister(gNameAttributeClass);
-
- return kQ3Failure;
- }
-
- /*
- * NameAttribute_MetaHandler
- */
- static TQ3FunctionPointer NameAttribute_MetaHandler(
- TQ3MethodType methodType)
- {
- switch (methodType)
- {
- case kQ3MethodTypeObjectTraverse:
- return (TQ3FunctionPointer) NameAttribute_Traverse;
- case kQ3MethodTypeObjectReadData:
- return (TQ3FunctionPointer) NameAttribute_ReadData;
- case kQ3MethodTypeElementCopyAdd:
- case kQ3MethodTypeElementCopyGet:
- case kQ3MethodTypeElementCopyDuplicate:
- return (TQ3FunctionPointer) NameAttribute_CopyAdd;
- case kQ3MethodTypeElementCopyReplace:
- return (TQ3FunctionPointer) NameAttribute_CopyReplace;
- case kQ3MethodTypeElementDelete:
- return (TQ3FunctionPointer) NameAttribute_Delete;
- default:
- return (TQ3FunctionPointer) NULL;
- }
- }
-
- /*
- * NameAttribute_Register
- */
- TQ3Status NameAttribute_Register(
- void)
- {
- gNameAttributeClass =
- Q3ElementClass_Register(
- kElementTypeName,
- "NameAttribute",
- sizeof(TQ3StringObject),
- NameAttribute_MetaHandler);
-
- return (gNameAttributeClass == NULL ? kQ3Failure : kQ3Success);
- }
-
- /**********************************************************************************************
- *
- * SCALE custom attribute
- *
- **********************************************************************************************/
-
- /*
- * Utility function to add a scale on an shape object, geometry object, or attribute set
- */
-
- TQ3Status SetScale(TQ3Object object, double scale)
- {
- TQ3AttributeSet set = NULL;
- TQ3Status status = kQ3Success;
-
- if( Q3Object_IsType(object, kQ3SharedTypeShape) == kQ3True ) {
-
- if( Q3Object_IsType(object, kQ3ShapeTypeGeometry) == kQ3True ) {
-
- Q3Geometry_GetAttributeSet(object, &set);
-
- if( set == NULL ) {
- set = Q3AttributeSet_New();
- if( set == NULL ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- Q3Geometry_SetAttributeSet(object, set);
- }
- } else {
- Q3Shape_GetSet(object, &set);
-
- if( set == NULL ) {
- set = Q3Set_New();
- if( set == NULL ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- Q3Shape_SetSet(object, set);
- }
- }
-
- if( Q3Set_Add(set, kElementTypeScale, &scale) == kQ3Failure ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- } else if( Q3Object_IsType(object, kQ3SharedTypeSet) == kQ3True ) {
- if( Q3AttributeSet_Add(object, kElementTypeScale, &scale) == kQ3Failure ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- } else
- status = kQ3Failure;
-
- cleanExit:
- if( set )
- Q3Object_Dispose(set);
- return status;
- }
-
- /*
- * ScaleAttribute_Traverse
- */
-
- static TQ3Status ScaleAttribute_Traverse(
- TQ3Object unused,
- TQ3Float64 *scale,
- TQ3ViewObject view)
- {
- (void) unused;
-
- if (scale == NULL)
- return kQ3Success;
-
- return Q3View_SubmitWriteData(
- view, sizeof(TQ3Float64), scale, NULL);
- }
-
- /*
- * ScaleAttribute_Write
- */
-
- static TQ3Status ScaleAttribute_Write(
- TQ3Float64 *scale,
- TQ3FileObject file)
- {
- return
- Q3Float64_Write(*scale, file);
- }
-
- /*
- * ScaleAttribute_ReadData
- */
-
- static TQ3Status ScaleAttribute_ReadData(
- TQ3SetObject attributeSet,
- TQ3FileObject file)
- {
- double scale;
-
- if( Q3Float64_Read(&scale, file) == kQ3Failure) {
- return kQ3Failure;
- }
-
- return Q3Set_Add(attributeSet, kElementTypeScale, &scale);
- }
-
- /*
- * ScaleAttribute_MetaHandler
- */
- static TQ3FunctionPointer ScaleAttribute_MetaHandler(
- TQ3MethodType methodType)
- {
- switch (methodType)
- {
- case kQ3MethodTypeObjectTraverse:
- return (TQ3FunctionPointer) ScaleAttribute_Traverse;
- case kQ3MethodTypeObjectWrite:
- return (TQ3FunctionPointer) ScaleAttribute_Write;
- case kQ3MethodTypeObjectReadData:
- return (TQ3FunctionPointer) ScaleAttribute_ReadData;
- default:
- return (TQ3FunctionPointer) NULL;
- }
- }
-
- /*
- * ScaleAttribute_Register
- */
- TQ3Status ScaleAttribute_Register(
- void)
- {
- gScaleAttributeClass =
- Q3ElementClass_Register(
- kElementTypeScale,
- "ScaleAttribute",
- sizeof(TQ3Float64),
- ScaleAttribute_MetaHandler);
-
- return (gScaleAttributeClass == NULL ? kQ3Failure : kQ3Success);
- }
-
- /*
- * ScaleAttribute_Unregister
- */
- TQ3Status ScaleAttribute_Unregister(
- void)
- {
- if ( gScaleAttributeClass != NULL )
- return Q3ObjectClass_Unregister(gScaleAttributeClass);
-
- return kQ3Failure;
- }
-
- /**********************************************************************************************
- *
- * common routines for dealing with vectors
- *
- **********************************************************************************************/
-
- static TQ3Status vector_Traverse(
- TQ3Object unused,
- TQ3Vector3D *upVector,
- TQ3ViewObject view)
- {
- (void) unused;
-
- if (upVector == NULL)
- return kQ3Success;
-
- return Q3View_SubmitWriteData(
- view, sizeof(TQ3Vector3D), upVector, NULL);
- }
-
- static TQ3Status vector_Write(
- TQ3Vector3D *upVector,
- TQ3FileObject file)
- {
- return
- Q3Vector3D_Write(upVector, file);
- }
-
- static TQ3Status vector_CopyAdd(
- TQ3Vector3D *src,
- TQ3Vector3D *dst)
- {
- *dst = *src;
- return kQ3Success;
- }
-
- static TQ3Status vector_CopyReplace(
- TQ3Vector3D *src,
- TQ3Vector3D *dst)
- {
- *dst = *src;
- return kQ3Success;
- }
-
- /**********************************************************************************************
- *
- * UP VECTOR custom attribute
- *
- **********************************************************************************************/
-
- /*
- * Utility function to specify the up vector on a group, geometry object, or attribute set
- */
-
- TQ3Status SetUpVector(TQ3Object object, TQ3Vector3D *upVector)
- {
- TQ3AttributeSet set = NULL;
- TQ3Status status = kQ3Success;
-
- if( Q3Object_IsType(object, kQ3ShapeTypeGeometry) == kQ3True ) {
- Q3Geometry_GetAttributeSet(object, &set);
-
- if( set == NULL ) {
- set = Q3AttributeSet_New();
- if( set == NULL ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- Q3Geometry_SetAttributeSet(object, set);
- }
- } else if( Q3Object_IsType(object, kQ3ShapeTypeGroup) == kQ3True ){
- Q3Shape_GetSet(object, &set);
-
- if( set == NULL ) {
- set = Q3Set_New();
- if( set == NULL ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- Q3Shape_SetSet(object, set);
- }
- }
-
- if( set ) {
- if( Q3Set_Add(set, kElementTypeUpVector, &upVector) == kQ3Failure ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- } else if( Q3Object_IsType(object, kQ3SharedTypeSet) == kQ3True ) {
- if( Q3AttributeSet_Add(object, kElementTypeUpVector, &upVector) == kQ3Failure ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- } else
- status = kQ3Failure;
-
- cleanExit:
- if( set )
- Q3Object_Dispose(set);
- return status;
- }
-
- /*
- * UpVectorAttribute_ReadData
- */
- static TQ3Status UpVectorAttribute_ReadData(
- TQ3SetObject attributeSet,
- TQ3FileObject file)
- {
- TQ3Vector3D upVector;
-
- if( Q3Vector3D_Read(&upVector, file) == kQ3Failure) {
- return kQ3Failure;
- }
-
- return Q3Set_Add(attributeSet, kElementTypeUpVector, &upVector);
- }
-
- /*
- * UpVectorAttribute_MetaHandler
- */
- static TQ3FunctionPointer UpVectorAttribute_MetaHandler(
- TQ3MethodType methodType)
- {
- switch (methodType)
- {
- case kQ3MethodTypeObjectTraverse:
- return (TQ3FunctionPointer) vector_Traverse;
- case kQ3MethodTypeObjectWrite:
- return (TQ3FunctionPointer) vector_Write;
- case kQ3MethodTypeObjectReadData:
- return (TQ3FunctionPointer) UpVectorAttribute_ReadData;
- case kQ3MethodTypeElementCopyAdd:
- case kQ3MethodTypeElementCopyGet:
- case kQ3MethodTypeElementCopyDuplicate:
- return (TQ3FunctionPointer) vector_CopyAdd;
- case kQ3MethodTypeElementCopyReplace:
- return (TQ3FunctionPointer) vector_CopyReplace;
- default:
- return (TQ3FunctionPointer) NULL;
- }
- }
-
- /*
- * UpVectorAttribute_Register
- */
- TQ3Status UpVectorAttribute_Register(
- void)
- {
- gUpVectorAttributeClass =
- Q3ElementClass_Register(
- kElementTypeUpVector,
- "UpVector",
- sizeof(TQ3Vector3D),
- UpVectorAttribute_MetaHandler);
-
- return (gUpVectorAttributeClass == NULL ? kQ3Failure : kQ3Success);
- }
-
- /*
- * UpVectorAttribute_Unregister
- */
- TQ3Status UpVectorAttribute_Unregister(
- void)
- {
- if ( gUpVectorAttributeClass != NULL )
- return Q3ObjectClass_Unregister(gUpVectorAttributeClass);
-
- return kQ3Failure;
- }
-
- /**********************************************************************************************
- *
- * FORWARD DIRECTION custom attribute
- *
- **********************************************************************************************/
- /*
- * Utility function to add a name on a group, geometry object, or attribute set
- */
-
- TQ3Status SetForwardDirection(TQ3Object object, TQ3Vector3D *forwardDirection)
- {
- TQ3AttributeSet set = NULL;
- TQ3Status status = kQ3Success;
-
- if( Q3Object_IsType(object, kQ3ShapeTypeGeometry) == kQ3True ) {
- Q3Geometry_GetAttributeSet(object, &set);
-
- if( set == NULL ) {
- set = Q3AttributeSet_New();
- if( set == NULL ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- Q3Geometry_SetAttributeSet(object, set);
- }
- } else if( Q3Object_IsType(object, kQ3ShapeTypeGroup) == kQ3True ){
- Q3Shape_GetSet(object, &set);
-
- if( set == NULL ) {
- set = Q3Set_New();
- if( set == NULL ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- Q3Shape_SetSet(object, set);
- }
- }
-
- if( set ) {
- if( Q3Set_Add(set, kElementTypeForwardDirection, &forwardDirection) == kQ3Failure ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- } else if( Q3Object_IsType(object, kQ3SharedTypeSet) == kQ3True ) {
- if( Q3AttributeSet_Add(object, kElementTypeForwardDirection, &forwardDirection) == kQ3Failure ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- } else
- status = kQ3Failure;
-
- cleanExit:
- if( set )
- Q3Object_Dispose(set);
- return status;
- }
-
- /*
- * ForwardDirectionAttribute_ReadData
- */
- static TQ3Status ForwardDirectionAttribute_ReadData(
- TQ3SetObject attributeSet,
- TQ3FileObject file)
- {
- TQ3Vector3D forwardDirection;
-
- if( Q3Vector3D_Read(&forwardDirection, file) == kQ3Failure) {
- return kQ3Failure;
- }
-
- return Q3Set_Add(attributeSet, kElementTypeForwardDirection, &forwardDirection);
- }
-
- /*
- * ForwardDirectionAttribute_MetaHandler
- */
- static TQ3FunctionPointer ForwardDirectionAttribute_MetaHandler(
- TQ3MethodType methodType)
- {
- switch (methodType)
- {
- case kQ3MethodTypeObjectTraverse:
- return (TQ3FunctionPointer) vector_Traverse;
- case kQ3MethodTypeObjectWrite:
- return (TQ3FunctionPointer) vector_Write;
- case kQ3MethodTypeObjectReadData:
- return (TQ3FunctionPointer) ForwardDirectionAttribute_ReadData;
- default:
- return (TQ3FunctionPointer) NULL;
- }
- }
-
- /*
- * ForwardDirectionAttribute_Register
- */
- TQ3Status ForwardDirectionAttribute_Register(
- void)
- {
- gUpVectorAttributeClass =
- Q3ElementClass_Register(
- kElementTypeForwardDirection,
- "ForwardDirection",
- sizeof(TQ3Vector3D),
- ForwardDirectionAttribute_MetaHandler);
-
- return (gForwardVectorAttributeClass == NULL ? kQ3Failure : kQ3Success);
- }
-
- /*
- * ForwardDirectionAttribute_Unregister
- */
- TQ3Status ForwardDirectionAttribute_Unregister(
- void)
- {
- if ( gForwardVectorAttributeClass != NULL )
- return Q3ObjectClass_Unregister(gForwardVectorAttributeClass);
-
- return kQ3Failure;
- }
-
- /***********************************************************************************************
- *
- * W3Anchor - This allows you attach an URL (universal resource locator) to an object or
- * group. If this attribute is attached to a group, it should be interpreted as applying
- * to all the objects inside the group.
- *
- *
- ***********************************************************************************************/
-
- /*
- * Utility function to attach an URL reference to a group object, geometry object, or attribute set
- */
-
- TQ3Status SetW3Anchor(TQ3Object object, char *url, char *description, W3AnchorOptions options)
- {
- TQ3StringObject string = NULL;
- TQ3AttributeSet set = NULL;
- TQ3Status status = kQ3Success;
- W3AnchorData W3Anchor;
-
- string = Q3CString_New(description);
-
- if( string == NULL) {
- status = kQ3Failure;
- goto cleanExit;
- }
-
- W3Anchor.description = string;
- W3Anchor.url = url;
- W3Anchor.options = options;
-
- if( Q3Object_IsType(object, kQ3ShapeTypeGeometry) == kQ3True ) {
-
- Q3Geometry_GetAttributeSet(object, &set);
-
- if( set == NULL ) {
- set = Q3AttributeSet_New();
- if( set == NULL ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- Q3Geometry_SetAttributeSet(object, set);
- }
- } else if( Q3Object_IsType(object, kQ3ShapeTypeGroup) == kQ3True ) {
- Q3Shape_GetSet(object, &set);
-
- if( set == NULL ) {
- set = Q3Set_New();
- if( set == NULL ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- Q3Shape_SetSet(object, set);
- }
- }
-
- if( set ) {
- if( Q3Set_Add(set, kElementTypeW3Anchor, &W3Anchor) == kQ3Failure ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- } else if( Q3Object_IsType(object, kQ3SharedTypeSet) == kQ3True ) {
- if( Q3AttributeSet_Add(object, kElementTypeW3Anchor, &W3Anchor) == kQ3Failure ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- } else
- status = kQ3Failure;
-
- cleanExit:
- if( set )
- Q3Object_Dispose(set);
- if( string )
- Q3Object_Dispose(string);
- return status;
- }
-
- TQ3Boolean W3Anchor_GetFromObject(
- TQ3Object object,
- W3AnchorData *data)
- {
- TQ3SetObject set, tempSet;
- TQ3Boolean result = kQ3False;
-
- W3Anchor_Empty (data);
- data->url = NULL;
- data->description = NULL;
-
- // must be a shape or a group
- if (Q3Object_IsType(object, kQ3ShapeTypeGeometry) == kQ3True)
- Q3Geometry_GetAttributeSet(object, &set);
- else if (Q3Object_IsType(object, kQ3SharedTypeShape) == kQ3True)
- Q3Shape_GetSet (object, &set);
- else
- return kQ3False;
-
- if (set == NULL)
- return kQ3False;
-
- while (set != NULL)
- {
- if (Q3Set_Contains (set, kElementTypeW3Anchor) == kQ3True)
- {
- if (Q3Set_Get(set, kElementTypeW3Anchor, data) == kQ3Success)
- result = kQ3True;
- break;
- }
- else if (Q3Set_Contains (set, kQ3SharedTypeSet) == kQ3True)
- {
- tempSet = set;
- if (Q3Set_Get (set, kQ3SharedTypeSet, &set) == kQ3Failure)
- break;
- else
- Q3Object_Dispose (tempSet);
- }
- /* This is to get around a bug in releases prior to 1.0.4 PFF */
- else if (Q3Set_Contains (set, kQ3ElementTypeUnknown) == kQ3True)
- {
- TQ3Object unknownObject;
-
- if (Q3Set_Get (set, kQ3ElementTypeUnknown, &unknownObject) != kQ3Failure)
- {
- TQ3ObjectType unknownType = Q3Object_GetLeafType (unknownObject);
-
- if (unknownType == kQ3SharedTypeSet)
- {
- Q3Object_Dispose (set);
- set = unknownObject;
- }
- else if (unknownType == kQ3GroupTypeDisplay)
- {
- TQ3GroupPosition position;
- Q3Group_GetFirstPositionOfType (unknownObject, kQ3SharedTypeSet, &position);
-
- if (position)
- {
- tempSet = set;
- if (Q3Group_GetPositionObject(unknownObject, position, &set) == kQ3Success)
- Q3Object_Dispose (tempSet);
- }
- Q3Object_Dispose (unknownObject);
- }
- else
- Q3Object_Dispose (unknownObject);
- }
- }
- else
- break;
- }
-
- // throw away the reference to the set
- Q3Object_Dispose(set);
-
- return result;
- }
-
- TQ3Boolean W3Anchor_GetFromHitData(
- const TQ3HitData *hitData,
- W3AnchorData *data)
- {
- if (data == NULL)
- return kQ3False;
-
- return W3Anchor_GetFromObject (hitData->object, data);
- }
-
- #ifdef __cplusplus
- extern "C" {
- #endif /* __cplusplus */
-
- TQ3Status W3Anchor_Traverse(
- TQ3Object unused,
- W3AnchorData *URLdata,
- TQ3ViewObject view);
-
- #ifdef __cplusplus
- }
- #endif /* __cplusplus */
-
- /*
- * W3Anchor_Traverse
- */
- TQ3Status W3Anchor_Traverse(
- TQ3Object unused,
- W3AnchorData *URLdata,
- TQ3ViewObject view)
- {
- TQ3Size size;
-
- (void) unused;
-
- if (URLdata->url == NULL)
- return kQ3Success;
-
- size = Q3Size_Pad(strlen(URLdata->url) + 1);
- size += sizeof(TQ3Uns32);
-
- if( Q3View_SubmitWriteData(view, size, URLdata, NULL) == kQ3Failure )
- return kQ3Failure;
-
- if(URLdata->description) {
- if( Q3Object_Submit(URLdata->description, view) == kQ3Failure )
- return kQ3Failure;
- }
-
- return kQ3Success;
- }
-
- /*
- * W3Anchor_Write
- */
- static TQ3Status W3Anchor_Write(
- W3AnchorData *URLdata,
- TQ3FileObject file)
- {
- return
- Q3String_Write(URLdata->url, file) == kQ3Success &&
- Q3Uns32_Write((unsigned long) URLdata->options, file) == kQ3Success ? kQ3Success : kQ3Failure;
- }
-
- /*
- * W3Anchor_ReadData
- */
- static TQ3Status W3Anchor_ReadData(
- TQ3SetObject set,
- TQ3FileObject file)
- {
- char buf[kQ3StringMaximumLength];
- W3AnchorData URLData = {NULL, NULL, kW3AnchorOptionNone};
-
- if (Q3String_Read(buf, NULL, file) == kQ3Failure)
- return kQ3Failure;
-
- URLData.url = (char *) malloc( strlen(buf) + 1);
- strcpy( URLData.url, buf);
-
- if (Q3Uns32_Read( (unsigned long *) &URLData.options, file) == kQ3Failure)
- return kQ3Failure;
-
- if( Q3File_IsEndOfContainer(file, NULL) == kQ3False ) {
- URLData.description = Q3File_ReadObject(file);
- }
-
- return Q3Set_Add(set, kElementTypeW3Anchor, &URLData);
- }
-
- /*
- * W3Anchor_CopyAdd
- */
- static TQ3Status W3Anchor_CopyAdd(
- W3AnchorData *src,
- W3AnchorData *dst)
- {
- long i;
-
- if (src->url == NULL)
- return kQ3Failure;
-
- i = strlen(src->url);
-
- if (i == 0)
- return kQ3Failure;
-
- dst->url = (char *) malloc(i + 1);
-
- if (dst->url == NULL)
- return kQ3Failure;
-
- strcpy(dst->url, src->url);
-
- if( src->description ) {
- TQ3StringObject stringReference;
-
- stringReference = Q3Shared_GetReference(src->description);
-
- if( stringReference == NULL) {
- return kQ3Failure;
- }
-
- dst->description = stringReference;
- } else
- dst->description = NULL;
-
- dst->options = src->options;
- return kQ3Success;
- }
-
- /*
- * W3Anchor_CopyReplace
- */
- static TQ3Status W3Anchor_CopyReplace(
- W3AnchorData *src,
- W3AnchorData *dst)
- {
- long i;
- char *c;
-
- if (src->url == NULL)
- return kQ3Failure;
-
- i = strlen(src->url);
-
- if (i == 0)
- return kQ3Failure;
-
- c = (char *) realloc(dst->url, i + 1);
-
- if (c == NULL)
- return kQ3Failure;
-
- dst->url = c;
-
- strcpy(dst->url, src->url);
-
- if( src->description ) {
- TQ3StringObject stringReference;
-
- stringReference = Q3Shared_GetReference(src->description);
-
- if( stringReference == NULL) {
- return kQ3Failure;
- }
-
- if( dst->description ) {
- Q3Object_Dispose(dst->description);
- }
-
- dst->description = stringReference;
- } else
- dst->description = NULL;
-
- dst->options = src->options;
- return kQ3Success;
- }
-
- /*
- * W3Anchor_Delete
- */
- static TQ3Status W3Anchor_Delete(
- W3AnchorData *URLData)
- {
- if (URLData->url != NULL)
- {
- free(URLData->url);
- URLData->url = NULL;
- }
- if (URLData->description != NULL)
- {
- Q3Object_Dispose(URLData->description);
- URLData->description = NULL;
- }
-
- return kQ3Success;
- }
-
- /*
- * W3Anchor_MetaHandler
- */
- static TQ3FunctionPointer W3Anchor_MetaHandler(
- TQ3MethodType methodType)
- {
- switch (methodType)
- {
- case kQ3MethodTypeObjectTraverse:
- return (TQ3FunctionPointer) W3Anchor_Traverse;
- case kQ3MethodTypeObjectWrite:
- return (TQ3FunctionPointer) W3Anchor_Write;
- case kQ3MethodTypeObjectReadData:
- return (TQ3FunctionPointer) W3Anchor_ReadData;
- case kQ3MethodTypeElementCopyAdd:
- case kQ3MethodTypeElementCopyGet:
- case kQ3MethodTypeElementCopyDuplicate:
- return (TQ3FunctionPointer) W3Anchor_CopyAdd;
- case kQ3MethodTypeElementCopyReplace:
- return (TQ3FunctionPointer) W3Anchor_CopyReplace;
- case kQ3MethodTypeElementDelete:
- return (TQ3FunctionPointer) W3Anchor_Delete;
- default:
- return (TQ3FunctionPointer) NULL;
- }
- }
-
- /*
- * W3Anchor_Register
- */
- TQ3Status W3Anchor_Register(
- void)
- {
- gW3AnchorClass =
- Q3ElementClass_Register(
- kElementTypeW3Anchor,
- "W3Anchor",
- sizeof(W3AnchorData),
- W3Anchor_MetaHandler);
-
- return (gW3AnchorClass == NULL ? kQ3Failure : kQ3Success);
- }
-
- TQ3Status W3Anchor_Unregister(
- void)
- {
- if(gW3AnchorClass)
- return Q3ObjectClass_Unregister(gW3AnchorClass);
- else
- return kQ3Success;
- }
-
- void W3Anchor_Empty (
- W3AnchorData *URLData)
- {
- if (URLData != NULL)
- W3Anchor_Delete (URLData);
- }
-
-
- /***********************************************************************************************
- *
- * W3Inline - Attach this to a proxy group or geometry
- *
- *
- ***********************************************************************************************/
-
- /*
- * Utility function to add a name on a group object, geometry object, or attribute set
- */
-
- TQ3Status SetW3Inline(TQ3Object object, char *url)
- {
- TQ3AttributeSet set = NULL;
- TQ3Status status = kQ3Success;
- W3InlineData W3Inline;
-
- W3Inline.url = url;
-
- if( Q3Object_IsType(object, kQ3ShapeTypeGeometry) == kQ3True ) {
- Q3Geometry_GetAttributeSet(object, &set);
-
- if( set == NULL ) {
- set = Q3AttributeSet_New();
- if( set == NULL ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- Q3Geometry_SetAttributeSet(object, set);
- }
- } else if( Q3Object_IsType(object, kQ3ShapeTypeGroup ) == kQ3True ) {
- Q3Shape_GetSet(object, &set);
-
- if( set == NULL ) {
- set = Q3Set_New();
- if( set == NULL ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- Q3Shape_SetSet(object, set);
- }
- }
-
- if( set ) {
- if( Q3Set_Add(set, kElementTypeW3Inline, &W3Inline) == kQ3Failure ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- } else if( Q3Object_IsType(object, kQ3SharedTypeSet) == kQ3True ) {
- if( Q3AttributeSet_Add(object, kElementTypeW3Inline, &W3Inline) == kQ3Failure ) {
- status = kQ3Failure;
- goto cleanExit;
- }
- } else
- status = kQ3Failure;
-
- cleanExit:
- if( set )
- Q3Object_Dispose(set);
- return status;
- }
-
- /*
- * Static Functions
- */
- static TQ3Status W3Inline_Traverse(
- TQ3Object unused,
- W3InlineData *inlineData,
- TQ3ViewObject view)
- {
- TQ3Size size;
-
- (void) unused;
-
- if (inlineData->url == NULL)
- return kQ3Success;
-
- size = Q3Size_Pad(strlen(inlineData->url) + 1);
-
- return
- Q3View_SubmitWriteData(view, size, inlineData, NULL);
- }
-
- static TQ3Status W3Inline_Write(
- W3InlineData *inlineData,
- TQ3FileObject file)
- {
- return
- Q3String_Write(inlineData->url, file) == kQ3Success &&
- Q3Comment_Write("url", file) == kQ3Success ? kQ3Success : kQ3Failure;
- }
-
- static TQ3Status W3Inline_ReadData(
- TQ3SetObject set,
- TQ3FileObject file)
- {
- char buf[kQ3StringMaximumLength];
- W3InlineData inlineData;
-
- if (Q3String_Read(buf, NULL, file) == kQ3Failure)
- return kQ3Failure;
-
- inlineData.url = buf;
-
- return Q3Set_Add(set, kElementTypeW3Inline, &inlineData);
- }
-
- static TQ3Status W3Inline_CopyAdd(
- W3InlineData *src,
- W3InlineData *dst)
- {
- long i;
-
- if (src->url == NULL)
- return kQ3Failure;
-
- i = strlen(src->url);
-
- if (i == 0)
- return kQ3Failure;
-
- dst->url = (char *) malloc(i + 1);
-
- if (dst->url == NULL)
- return kQ3Failure;
-
- strcpy(dst->url, src->url);
-
- return kQ3Success;
- }
-
- static TQ3Status W3Inline_CopyReplace(
- W3InlineData *src,
- W3InlineData *dst)
- {
- long i;
- char *c;
-
- if (src->url == NULL)
- return kQ3Failure;
-
- i = strlen(src->url);
-
- if (i == 0)
- return kQ3Failure;
-
- c = (char *) realloc(dst->url, i + 1);
-
- if (c == NULL)
- return kQ3Failure;
-
- dst->url = c;
-
- strcpy(dst->url, src->url);
-
- return kQ3Success;
- }
-
- static TQ3Status W3Inline_Delete(
- W3InlineData *src)
- {
- if (src->url != NULL)
- free(src->url);
-
- return kQ3Success;
- }
-
- /*
- * W3Inline_MetaHandler
- */
- static TQ3FunctionPointer W3Inline_MetaHandler(
- TQ3MethodType methodType)
- {
- switch (methodType)
- {
- case kQ3MethodTypeObjectTraverse:
- return (TQ3FunctionPointer) W3Inline_Traverse;
- case kQ3MethodTypeObjectWrite:
- return (TQ3FunctionPointer) W3Inline_Write;
- case kQ3MethodTypeObjectReadData:
- return (TQ3FunctionPointer) W3Inline_ReadData;
- case kQ3MethodTypeElementCopyAdd:
- case kQ3MethodTypeElementCopyGet:
- case kQ3MethodTypeElementCopyDuplicate:
- return (TQ3FunctionPointer) W3Inline_CopyAdd;
- case kQ3MethodTypeElementCopyReplace:
- return (TQ3FunctionPointer) W3Inline_CopyReplace;
- case kQ3MethodTypeElementDelete:
- return (TQ3FunctionPointer) W3Inline_Delete;
- default:
- return (TQ3FunctionPointer) NULL;
- }
- }
-
- /*
- * W3Inline_Register
- */
- TQ3Status W3Inline_Register(
- void)
- {
- gW3InlineClass =
- Q3ElementClass_Register(
- kElementTypeW3Inline,
- "W3Inline",
- sizeof(W3InlineData),
- W3Inline_MetaHandler);
-
- return (gW3InlineClass == NULL ? kQ3Failure : kQ3Success);
- }
-
- TQ3Status W3Inline_Unregister(
- void)
- {
- return Q3ObjectClass_Unregister(gW3InlineClass);
- }
-
-
- /***********************************************************************************************
- *
- * This one is obsolete. The code below will convert to the new type on reading and writing
- *
- *
- ***********************************************************************************************/
-
- /*
- * Static Functions
- */
- static TQ3Status WWWAnchor_Traverse(
- TQ3Object unused,
- WWWAnchorData *wwwdata,
- TQ3ViewObject view)
- {
- TQ3Size size;
-
- (void)unused;
- if (wwwdata->url == NULL)
- return kQ3Success;
-
- size = Q3Size_Pad(strlen(wwwdata->url) + 1);
-
- return
- Q3View_SubmitWriteData(view, size, wwwdata, NULL);
- }
-
- static TQ3Status WWWAnchor_Write(
- WWWAnchorData *wwwdata,
- TQ3FileObject file)
- {
- return
- Q3String_Write(wwwdata->url, file) == kQ3Success &&
- Q3Comment_Write("url", file) == kQ3Success ? kQ3Success : kQ3Failure;
- }
-
- static TQ3Status WWWAnchor_ReadData(
- TQ3SetObject set,
- TQ3FileObject file)
- {
- char buf[kQ3StringMaximumLength];
- WWWAnchorData wwwdata;
- W3AnchorData W3Anchor;
-
- if (Q3String_Read(buf, NULL, file) == kQ3Failure)
- return kQ3Failure;
-
- wwwdata.url = (char *) malloc(strlen(buf) + 1);
- strcpy(wwwdata.url, buf);
-
- W3Anchor.url = (char *) malloc(strlen(buf) + 1);
- strcpy(W3Anchor.url, buf);
-
- W3Anchor.description = NULL;
- W3Anchor.options = kW3AnchorOptionNone;
-
- Q3Set_Add(set, kElementTypeW3Anchor, &W3Anchor);
-
- return Q3Set_Add(set, kElementTypeWWWAnchor, &wwwdata);
- }
-
- static TQ3Status WWWAnchor_CopyAdd(
- WWWAnchorData *src,
- WWWAnchorData *dst)
- {
- long i;
-
- if (src->url == NULL)
- return kQ3Failure;
-
- i = strlen(src->url);
-
- if (i == 0)
- return kQ3Failure;
-
- dst->url = (char *) malloc(i + 1);
-
- if (dst->url == NULL)
- return kQ3Failure;
-
- strcpy(dst->url, src->url);
-
- return kQ3Success;
- }
-
- static TQ3Status WWWAnchor_CopyReplace(
- WWWAnchorData *src,
- WWWAnchorData *dst)
- {
- long i;
- char *c;
-
- if (src->url == NULL)
- return kQ3Failure;
-
- i = strlen(src->url);
-
- if (i == 0)
- return kQ3Failure;
-
- c = (char *) realloc(dst->url, i + 1);
-
- if (c == NULL)
- return kQ3Failure;
-
- dst->url = c;
-
- strcpy(dst->url, src->url);
-
- return kQ3Success;
- }
-
- static TQ3Status WWWAnchor_Delete(
- WWWAnchorData *src)
- {
- if (src->url != NULL)
- free(src->url);
-
- return kQ3Success;
- }
-
- /*
- * WWWAnchor_MetaHandler
- */
- static TQ3FunctionPointer WWWAnchor_MetaHandler(
- TQ3MethodType methodType)
- {
- switch (methodType)
- {
- case kQ3MethodTypeObjectTraverse:
- return (TQ3FunctionPointer) WWWAnchor_Traverse;
- case kQ3MethodTypeObjectWrite:
- return (TQ3FunctionPointer) WWWAnchor_Write;
- case kQ3MethodTypeObjectReadData:
- return (TQ3FunctionPointer) WWWAnchor_ReadData;
- case kQ3MethodTypeElementCopyAdd:
- case kQ3MethodTypeElementCopyGet:
- case kQ3MethodTypeElementCopyDuplicate:
- return (TQ3FunctionPointer) WWWAnchor_CopyAdd;
- case kQ3MethodTypeElementCopyReplace:
- return (TQ3FunctionPointer) WWWAnchor_CopyReplace;
- case kQ3MethodTypeElementDelete:
- return (TQ3FunctionPointer) WWWAnchor_Delete;
- default:
- return (TQ3FunctionPointer) NULL;
- }
- }
-
- /*
- * WWWAnchor_Register
- */
- TQ3Status WWWAnchor_Register(
- void)
- {
- gWWWAnchorClass =
- Q3ElementClass_Register(
- kElementTypeWWWAnchor,
- kElementNameWWWAnchor,
- sizeof(WWWAnchorData),
- WWWAnchor_MetaHandler);
-
- return (gWWWAnchorClass == NULL ? kQ3Failure : kQ3Success);
- }
-
- TQ3Status WWWAnchor_Unregister(
- void)
- {
- return Q3ObjectClass_Unregister(gWWWAnchorClass);
- }
-